/*
*	Copyright (C) 2014  Julio Montes, Mario Carrillo
*	
*	Julio Montes e-mail: imc.coder@gmail.com 
*
*	Mario Carrillo e-mail: mario_90ago@live.com.mx
*
*	BSD 3-Clause License
*/

#include "include/iaSettingsEditorDialog.h"

#include "include/iaManager.h"
#include "sdk/include/filecfg.h"
#include "sdk/include/editor.h"
#include "sdk/include/cfgmgr.h"


#include <wx/fontdlg.h>
#include <wx/colordlg.h>
#include <wx/notebook.h>

BEGIN_EVENT_TABLE( iaSettingsEditorDialog, wxDialog )
    EVT_BUTTON( wxID_OK, iaSettingsEditorDialog::OnOk )
END_EVENT_TABLE()

iaSettingsEditorDialog::iaSettingsEditorDialog( wxWindow *parent )
    : wxDialog( parent, wxID_ANY, wxT( "Settings editor" ), wxDefaultPosition, wxSize( 700, wxSystemSettings::GetMetric( wxSYS_SCREEN_Y )-50 ) )
{
    wxBoxSizer *bsVertical = new wxBoxSizer( wxVERTICAL );

    wxNotebook *notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_LEFT | wxNB_FIXEDWIDTH );
    iaSettingsScrolledWindow *sg = new iaSettingsGeneral( notebook );
    vectorScrolled.push_back( sg );
    notebook->AddPage( sg, wxT( "General" ) );

    iaSettingsScrolledWindow *scc = new iaSettingsCodeCompletion( notebook );
    vectorScrolled.push_back( scc );
    notebook->AddPage( scc, wxT( "Code-Completion" ) );

    iaSettingsScrolledWindow *sf = new iaSettingsFold( notebook );
    vectorScrolled.push_back( sf );
    notebook->AddPage( sf, wxT( "Folding" ) );

    bsVertical->Add( notebook, 1, wxEXPAND );


    wxBoxSizer *bsButtons = new wxBoxSizer( wxHORIZONTAL );

    wxButton *btnOk = new wxButton( this, wxID_OK );
    wxButton *btnCancel = new wxButton( this, wxID_CANCEL );
    bsButtons->Add( btnCancel, 0, wxTOP | wxBOTTOM | wxRIGHT, 10 );
    bsButtons->Add( btnOk, 0, wxTOP | wxBOTTOM | wxRIGHT, 10 );
    bsVertical->Add( bsButtons, 0, wxALIGN_RIGHT );


    SetSizer( bsVertical );

}

iaSettingsEditorDialog::~iaSettingsEditorDialog()
{

}

void iaSettingsEditorDialog::OnOk( wxCommandEvent &evt )
{
    for( size_t i=0; i<vectorScrolled.size(); ++i )
        vectorScrolled[i]->WriteConfig();

    sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig )->Save();

    EndModal( wxID_OK );
}




/// GENERAL
iaSettingsGeneral::iaSettingsGeneral( wxWindow *parent )
    : iaSettingsScrolledWindow( parent )
{
    wxBoxSizer *bsH1 = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer *bsH2 = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer *bsH3 = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer *bsVertical = new wxBoxSizer( wxVERTICAL );

    iaSettingsPanel *fp = new iaFontPanel( this );
    vectorPanel.push_back( fp );
    bsVertical->Add( fp, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 20 );

    iaSettingsPanel *ip = new iaIndentPanel( this );
    vectorPanel.push_back( ip );
    bsH1->Add( ip, 1, wxEXPAND | wxTOP | wxLEFT, 20 );
    bsH1->AddSpacer( 10 );
    iaSettingsPanel *hop = new iaHighlightOccurrencesPanel( this );
    vectorPanel.push_back( hop );
    bsH1->Add( hop, 1, wxEXPAND | wxTOP | wxRIGHT, 20 );

    bsVertical->Add( bsH1, 0, wxEXPAND );


    iaSettingsPanel *tp = new iaTabPanel( this );
    vectorPanel.push_back( tp );
    bsH2->Add( tp, 1, wxEXPAND | wxTOP | wxLEFT, 20 );
    bsH2->AddSpacer( 10 );
    iaSettingsPanel *eofp = new iaEOFPanel( this );
    vectorPanel.push_back( eofp );
    bsH2->Add( eofp, 1, wxEXPAND | wxTOP | wxRIGHT, 20 );

    bsVertical->Add( bsH2, 0, wxEXPAND );




    iaSettingsPanel *ep = new iaEdgePanel( this );
    vectorPanel.push_back( ep );
    bsH3->Add( ep, 1, wxEXPAND | wxTOP | wxLEFT, 20 );
    bsH3->AddSpacer( 10 );
    iaSettingsPanel *cp = new iaCaretPanel( this );
    vectorPanel.push_back( cp );
    bsH3->Add( cp, 1, wxEXPAND | wxTOP | wxRIGHT, 20 );

    bsVertical->Add( bsH3, 0, wxEXPAND );


    iaSettingsPanel *op = new iaOthersPanel( this );
    vectorPanel.push_back( op );
    bsVertical->Add( op, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 20 );

    SetSizer( bsVertical );
    FitInside();
    SetScrollRate( 5, 5 );
}

iaSettingsGeneral::~iaSettingsGeneral()
{
}

void iaSettingsGeneral::WriteConfig()
{
    for( size_t i=0; i<vectorPanel.size(); ++i )
        vectorPanel[i]->WriteConfig();
}





BEGIN_EVENT_TABLE( iaFontPanel, iaSettingsPanel )
    EVT_BUTTON( iaID_CHOOSE, iaFontPanel::OnChoose )
END_EVENT_TABLE()


iaFontPanel::iaFontPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    font.SetPointSize( configEditor->ReadInt( wxT( "/config/general/font/size" ), 10 ) );
    font.SetStyle( configEditor->ReadBool( wxT( "/config/general/font/italic" ), false ) ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL );
    font.SetWeight( configEditor->ReadBool( wxT( "/config/general/font/bold" ), false ) ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL );
    font.SetFaceName( configEditor->ReadString( wxT( "/config/general/font/facename" ), wxT( "Monospace" ) ) );
    font.SetDefaultEncoding( static_cast<wxFontEncoding>( configEditor->ReadInt( wxT( "/config/other/encoding" ), 41 ) ) );

    wxButton *btnChoose = new wxButton( this, iaID_CHOOSE, wxT( "Choose" ) );
    wxStaticBoxSizer *sbs = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT( " Font " ) );
    stSampleText = new wxStaticText( this, wxID_ANY, wxT( "This is sample text" ) );
    stSampleText->SetFont( font );

    sbs->Add( stSampleText, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10  );
    sbs->Add( btnChoose, 0, wxALIGN_CENTER_VERTICAL | wxALL, 15 );

    SetSizer( sbs );
}

iaFontPanel::~iaFontPanel()
{
}

void iaFontPanel::OnChoose( wxCommandEvent &evt )
{
    wxFontData data;
    data.SetInitialFont( font );
    wxFontDialog dlg( this, data );
    if( dlg.ShowModal() == wxID_OK )
    {
        font= dlg.GetFontData().GetChosenFont();
        stSampleText->SetFont( font );
    }
}

void iaFontPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    configEditor->WriteInt( wxT( "/config/general/font/size" ), font.GetPointSize() );
    configEditor->WriteBool( wxT( "/config/general/font/italic" ), font.GetStyle() != wxFONTSTYLE_ITALIC ? false : true );
    configEditor->WriteBool( wxT( "/config/general/font/bold" ), font.GetWeight() != wxFONTWEIGHT_BOLD ? false : true );
    configEditor->WriteString( wxT( "/config/general/font/facename" ), font.GetFaceName() );
}







iaIndentPanel::iaIndentPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxStaticBoxSizer *sbs = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " Indent options " ) );

    cbShowGuides = new wxCheckBox( this, wxID_ANY, wxT( "Show guides" ) );
    cbShowGuides->SetValue( configEditor->ReadBool( wxT( "/config/general/indentbrace/guides" ), false ) );

    cbBackspaceUnindent = new wxCheckBox( this, wxID_ANY, wxT( "Backspace unindent" ) );
    cbBackspaceUnindent->SetValue( configEditor->ReadBool( wxT( "/config/general/indentbrace/backspaceunindent" ), true ) );

    cbBraceMatch = new wxCheckBox( this, wxID_ANY, wxT( "Highlight brace match" ) );
    cbBraceMatch->SetValue( configEditor->ReadBool( wxT( "/config/general/indentbrace/hilghtmatch" ), true ) );

    cbBraceCompletion = new wxCheckBox( this, wxID_ANY, wxT( "Brace completion" ) );
    cbBraceCompletion->SetValue( configEditor->ReadBool( wxT( "/config/general/indentbrace/autocomp" ), true ) );

    sbs->Add( cbShowGuides, 0, wxEXPAND | wxLEFT | wxTOP, 10 );
    sbs->Add( cbBackspaceUnindent, 0, wxEXPAND | wxLEFT, 10 );
    sbs->Add( cbBraceMatch, 0, wxEXPAND | wxLEFT, 10 );
    sbs->Add( cbBraceCompletion, 0, wxEXPAND | wxLEFT, 10 );

    SetSizer( sbs );
}

iaIndentPanel::~iaIndentPanel()
{
}

void iaIndentPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    configEditor->WriteBool( wxT( "/config/general/indentbrace/guides" ), cbShowGuides->GetValue() );
    configEditor->WriteBool( wxT( "/config/general/indentbrace/backspaceunindent" ), cbBackspaceUnindent->GetValue() );
    configEditor->WriteBool( wxT( "/config/general/indentbrace/hilghtmatch" ), cbBraceMatch->GetValue() );
    configEditor->WriteBool( wxT( "/config/general/indentbrace/autocomp" ), cbBraceCompletion->GetValue() );
}







BEGIN_EVENT_TABLE( iaHighlightOccurrencesPanel, iaSettingsPanel )
    EVT_CHECKBOX( iaID_HIGHLIGHTOCCURRENCES, iaHighlightOccurrencesPanel::OnHighlight )
    EVT_BUTTON( iaID_BTN_HIGHLIGHT, iaHighlightOccurrencesPanel::OnButtonHighlight )
END_EVENT_TABLE()


iaHighlightOccurrencesPanel::iaHighlightOccurrencesPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxStaticBoxSizer *sbs = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " Highlight Occurrences " ) );

    const bool flagShow = configEditor->ReadBool( wxT( "/config/general/hilghtoccurrence/enabled" ), true );

    cbHighlightOccurrences = new wxCheckBox( this, iaID_HIGHLIGHTOCCURRENCES, wxT( "Highlight occurrences" ) );
    cbHighlightOccurrences->SetValue( flagShow );

    cbCaseSensitive = new wxCheckBox( this, wxID_ANY, wxT( "Case sensitive" ) );
    cbCaseSensitive->SetValue( configEditor->ReadBool( wxT( "/config/general/hilghtoccurrence/casesensitive" ), true ) );

    cbWholeWord = new wxCheckBox( this, wxID_ANY, wxT( "Whole word" ) );
    cbWholeWord->SetValue( configEditor->ReadBool( wxT( "/config/general/hilghtoccurrence/wholeword" ), true ) );

    stHighlightColour = new wxStaticText( this, wxID_ANY, wxT( "Highlight colour" ) );
    btnColour = new wxButton( this, iaID_BTN_HIGHLIGHT, wxT( "..." ) );
    btnColour->SetBackgroundColour( configEditor->ReadColour( wxT( "/config/general/hilghtoccurrence/colour" ), wxColor( wxT( "#FF0000" ) ) ) );
    wxBoxSizer *bsHorizontal = new wxBoxSizer( wxHORIZONTAL );
    bsHorizontal->Add( stHighlightColour, 0, wxALIGN_CENTER_VERTICAL );
    bsHorizontal->Add( btnColour, 0, wxEXPAND | wxLEFT, 10 );


    sbs->Add( cbHighlightOccurrences, 0, wxEXPAND | wxLEFT | wxTOP, 10 );
    sbs->Add( cbCaseSensitive, 0, wxEXPAND | wxLEFT, 30 );
    sbs->Add( cbWholeWord, 0, wxEXPAND | wxLEFT, 30 );
    sbs->Add( bsHorizontal, 0, wxEXPAND | wxLEFT, 35 );


    SetSizer( sbs );

    cbCaseSensitive->Enable( flagShow );
    cbWholeWord->Enable( flagShow );
    stHighlightColour->Enable( flagShow );
    btnColour->Enable( flagShow );
}


iaHighlightOccurrencesPanel::~iaHighlightOccurrencesPanel()
{

}

void iaHighlightOccurrencesPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    if( cbHighlightOccurrences->GetValue() )
    {
        configEditor->WriteBool( wxT( "/config/general/hilghtoccurrence/enabled" ), true );
        configEditor->WriteBool( wxT( "/config/general/hilghtoccurrence/casesensitive" ), cbCaseSensitive->GetValue() );
        configEditor->WriteBool( wxT( "/config/general/hilghtoccurrence/wholeword" ), cbWholeWord->GetValue() );
        configEditor->WriteColour( wxT( "/config/general/hilghtoccurrence/colour" ), btnColour->GetBackgroundColour() );
    }
    else
        configEditor->WriteBool( wxT( "/config/general/hilghtoccurrence/enabled" ), false );

}

void iaHighlightOccurrencesPanel::OnHighlight( wxCommandEvent &evt )
{
    cbCaseSensitive->Enable( evt.IsChecked() );
    cbWholeWord->Enable( evt.IsChecked() );
    stHighlightColour->Enable( evt.IsChecked() );
    btnColour->Enable( evt.IsChecked() );
}

void iaHighlightOccurrencesPanel::OnButtonHighlight( wxCommandEvent &evt )
{
    wxColourData data;
    data.SetColour( btnColour->GetBackgroundColour() );
    wxColourDialog dlg( this, &data );

    if( dlg.ShowModal() == wxID_OK )
        btnColour->SetBackgroundColour( dlg.GetColourData().GetColour() );
}









iaTabPanel::iaTabPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxStaticBoxSizer *sbs = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " TAB options " ) );

    cbUseTabCharacter = new wxCheckBox( this, wxID_ANY, wxT( "Use TAB character" ) );
    cbUseTabCharacter->SetValue( configEditor->ReadBool( wxT( "/config/general/tab/usetabs" ), true ) );

    cbTabIndents = new wxCheckBox( this, wxID_ANY, wxT( "TAB indents" ) );
    cbTabIndents->SetValue( configEditor->ReadBool( wxT( "/config/general/tab/tabindents" ), true ) );

    stTabSize = new wxStaticText( this, wxID_ANY, wxT( "TAB size" ) );
    scTabSize = new wxSpinCtrl( this, wxID_ANY );
    scTabSize->SetRange( 1, 16 );
    scTabSize->SetValue( configEditor->ReadInt( wxT( "/config/general/tab/tabsize" ), 4 ) );
    wxBoxSizer *bsHorizontal = new wxBoxSizer( wxHORIZONTAL );
    bsHorizontal->Add( stTabSize, 0, wxALIGN_CENTER_VERTICAL );
    bsHorizontal->Add( scTabSize, 0, wxLEFT, 10 );


    sbs->Add( cbUseTabCharacter, 0, wxEXPAND | wxLEFT | wxTOP, 10 );
    sbs->Add( cbTabIndents, 0, wxEXPAND | wxLEFT, 10 );
    sbs->Add( bsHorizontal, 0, wxEXPAND | wxLEFT, 35 );
    sbs->AddSpacer( 5 );

    SetSizer( sbs );
}

iaTabPanel::~iaTabPanel()
{

}

void iaTabPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    configEditor->WriteBool( wxT( "/config/general/tab/usetabs" ), cbUseTabCharacter->GetValue() );
    configEditor->WriteBool( wxT( "/config/general/tab/tabindents" ), cbTabIndents->GetValue() );
    configEditor->WriteInt( wxT( "/config/general/tab/tabsize" ), scTabSize->GetValue() );
}








iaEOFPanel::iaEOFPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxStaticBoxSizer *sbs = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " EOF options " ) );

    cbShowEOF = new wxCheckBox( this, wxID_ANY, wxT( "Show EOL chars" ) );
    cbShowEOF->SetValue( configEditor->ReadBool( wxT( "/config/general/eofoptions/showeolchars" ), false ) );
    cbStrip = new wxCheckBox( this, wxID_ANY, wxT( "Strip trailing blanks" ) );
    cbStrip->SetValue( configEditor->ReadBool( wxT( "/config/general/eofoptions/striptb" ), true ) );
    cbEndWithBL = new wxCheckBox( this, wxID_ANY, wxT( "End files with blank line" ) );
    cbEndWithBL->SetValue( configEditor->ReadBool( wxT( "/config/general/eofoptions/endwithbl" ), true ) );

    sbs->Add( cbShowEOF, 0, wxEXPAND | wxLEFT | wxTOP, 10 );
    sbs->Add( cbStrip, 0, wxEXPAND | wxLEFT, 10 );
    sbs->Add( cbEndWithBL, 0, wxEXPAND | wxLEFT, 10 );

    SetSizer( sbs );
}

iaEOFPanel::~iaEOFPanel()
{

}

void iaEOFPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    configEditor->WriteBool( wxT( "/config/general/eofoptions/showeolchars" ), cbShowEOF->GetValue() );
    configEditor->WriteBool( wxT( "/config/general/eofoptions/striptb" ), cbStrip->GetValue() );
    configEditor->WriteInt( wxT( "/config/general/eofoptions/endwithbl" ), cbEndWithBL->GetValue() );
}





BEGIN_EVENT_TABLE( iaEdgePanel, iaSettingsPanel )
    EVT_CHECKBOX( iaID_CHBOX_SL, iaEdgePanel::OnShowLine )
    EVT_BUTTON( iaID_BTN_COLOUR, iaEdgePanel::OnButtonColour )
END_EVENT_TABLE()

iaEdgePanel::iaEdgePanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxStaticBoxSizer *sbs = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " Edge options " ) );
    wxBoxSizer *bsH1 = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer *bsH2 = new wxBoxSizer( wxHORIZONTAL );

    const bool flagShow = configEditor->ReadBool( wxT( "/config/general/edge/line" ), true );
    cbShowLine = new wxCheckBox( this, iaID_CHBOX_SL, wxT( "Show line" ) );
    sbs->Add( cbShowLine, 0, wxEXPAND | wxTOP | wxLEFT, 10 );
    cbShowLine->SetValue( flagShow );



    stColour = new wxStaticText( this, wxID_ANY, wxT( "Colour" ) );
    btnColour = new wxButton( this, iaID_BTN_COLOUR, wxT( "..." ) );
    btnColour->SetBackgroundColour( configEditor->ReadColour( wxT( "/config/general/edge/colour" ), wxColour( wxT( "#E0E0E0" ) ) ) );
    bsH2->AddSpacer( 10 );
    bsH2->Add( stColour, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10 );
    bsH2->Add( btnColour, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10 );
    sbs->Add( bsH2, 0, wxEXPAND | wxTOP, 5 );



    stColumnNumber = new wxStaticText( this, wxID_ANY, wxT( "Column number" ) );
    scColumnNumber = new wxSpinCtrl( this, wxID_ANY );
    scColumnNumber->SetRange( 0, 180 );
    scColumnNumber->SetValue( configEditor->ReadInt( wxT( "/config/general/edge/column" ), 80 ) );
    bsH1->AddSpacer( 10 );
    bsH1->Add( stColumnNumber, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10 );
    bsH1->Add( scColumnNumber, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10 );
    sbs->Add( bsH1, 0, wxEXPAND | wxTOP, 10 );


    SetSizer( sbs );

    stColumnNumber->Enable( flagShow );
    scColumnNumber->Enable( flagShow );
    stColour->Enable( flagShow );
    btnColour->Enable( flagShow );
}

iaEdgePanel::~iaEdgePanel()
{

}


void iaEdgePanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    if( cbShowLine->GetValue() )
    {
        configEditor->WriteBool( wxT( "/config/general/edge/line" ), true );
        configEditor->WriteInt( wxT( "/config/general/edge/column" ), scColumnNumber->GetValue() );
        configEditor->WriteColour( wxT( "/config/general/edge/colour" ), btnColour->GetBackgroundColour() );
    }
    else
        configEditor->WriteBool( wxT( "/general/edge/line" ), false );
}


void iaEdgePanel::OnShowLine( wxCommandEvent &evt )
{
    const bool check = evt.IsChecked();

    stColumnNumber->Enable( check );
    scColumnNumber->Enable( check );

    stColour->Enable( check );
    btnColour->Enable( check );
}

void iaEdgePanel::OnButtonColour( wxCommandEvent &evt )
{
    wxColourData data;
    data.SetColour( btnColour->GetBackgroundColour() );
    wxColourDialog dlg( this, &data );

    if( dlg.ShowModal() == wxID_OK )
        btnColour->SetBackgroundColour( dlg.GetColourData().GetColour() );
}









BEGIN_EVENT_TABLE( iaCaretPanel, iaSettingsPanel )
    EVT_CHECKBOX( iaID_CARET_LINEHIGHLIGHT, iaCaretPanel::OnLineHighlight )
    EVT_BUTTON( iaID_BTN_CARET_LINEHIGHLIGHT, iaCaretPanel::OnButtonColour )
END_EVENT_TABLE()

iaCaretPanel::iaCaretPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxStaticBoxSizer *sbs = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " Caret options " ) );

    stWidth = new wxStaticText( this, wxID_ANY, wxT( "Width of caret" ) );
    scWidth = new wxSpinCtrl( this );
    scWidth->SetRange( 1, 3 );
    scWidth->SetValue( configEditor->ReadInt( wxT( "/config/general/caretoptions/width" ), 1 ) );
    wxBoxSizer *bsH1 = new wxBoxSizer( wxHORIZONTAL );
    bsH1->Add( stWidth, 0, wxALIGN_CENTER_VERTICAL );
    bsH1->Add( scWidth, 0, wxLEFT, 10 );
    sbs->Add( bsH1, 0, wxEXPAND | wxTOP | wxLEFT, 10 );

    stPeriod = new wxStaticText( this, wxID_ANY, wxT( "time caret blinking" ) );
    scPeriod = new wxSpinCtrl( this );
    scPeriod->SetRange( 0, 1000 );
    scPeriod->SetValue( configEditor->ReadInt( wxT( "/config/general/caretoptions/period" ), 500 ) );
    wxBoxSizer *bsH2 = new wxBoxSizer( wxHORIZONTAL );
    bsH2->Add( stPeriod, 0, wxALIGN_CENTER_VERTICAL );
    bsH2->Add( scPeriod, 0, wxLEFT, 10 );
    sbs->Add( bsH2, 0, wxEXPAND | wxTOP | wxLEFT, 10 );

    bool flagHighlight = configEditor->ReadBool( wxT( "/config/general/caretoptions/hilghtline" ), false );
    cbHighlightline = new wxCheckBox( this, iaID_CARET_LINEHIGHLIGHT, wxT( "Highlight line of caret" ) );
    cbHighlightline->SetValue( flagHighlight );
    sbs->Add( cbHighlightline, 0, wxEXPAND | wxTOP | wxLEFT, 10 );

    stHighlightlineColour = new wxStaticText( this, wxID_ANY, wxT( "Highlight colour" ) );
    btnHighlightlineColour = new wxButton( this, iaID_BTN_CARET_LINEHIGHLIGHT, wxT( "..." ) );
    btnHighlightlineColour->SetBackgroundColour( configEditor->ReadColour( wxT( "/config/general/caretoptions/hilghtlinecolour" ), wxColour( wxT( "#FFFF00" ) ) ) );
    wxBoxSizer *bsH3 = new wxBoxSizer( wxHORIZONTAL );
    bsH3->AddSpacer( 35 );
    bsH3->Add( stHighlightlineColour, 0, wxALIGN_CENTER_VERTICAL );
    bsH3->Add( btnHighlightlineColour, 0, wxLEFT, 10 );
    sbs->Add( bsH3, 0, wxEXPAND | wxTOP, 5 );

    SetSizer( sbs );

    stHighlightlineColour->Enable( flagHighlight );
    btnHighlightlineColour->Enable( flagHighlight );

}

iaCaretPanel::~iaCaretPanel()
{

}

void iaCaretPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    configEditor->WriteInt( wxT( "/config/general/caretoptions/width" ), scWidth->GetValue() );
    configEditor->WriteInt( wxT( "/config/general/caretoptions/period" ), scPeriod->GetValue() );

    if( cbHighlightline->GetValue() )
    {
        configEditor->WriteBool( wxT( "/config/general/caretoptions/hilghtline" ), true );
        configEditor->WriteColour( wxT( "/config/general/caretoptions/hilghtlinecolour" ), btnHighlightlineColour->GetBackgroundColour() );
    }
    else
        configEditor->WriteBool( wxT( "/config/general/caretoptions/hilghtline" ), false );
}

void iaCaretPanel::OnLineHighlight( wxCommandEvent &evt )
{
    stHighlightlineColour->Enable( evt.IsChecked() );
    btnHighlightlineColour->Enable( evt.IsChecked() );
}

void iaCaretPanel::OnButtonColour( wxCommandEvent &evt )
{
    wxColourData data;
    data.SetColour( btnHighlightlineColour->GetBackgroundColour() );
    wxColourDialog dlg( this, &data );

    if( dlg.ShowModal() == wxID_OK )
        btnHighlightlineColour->SetBackgroundColour( dlg.GetColourData().GetColour() );
}







iaOthersPanel::iaOthersPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxStaticBoxSizer *sbs = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " Others options " ) );

    stEncoding = new wxStaticText( this, wxID_ANY, wxT( "Encoding when opening files" ) );
    cbEncoding = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 88, sdk::Editor::FontEncodingString, wxCB_READONLY );
    cbEncoding->SetSelection( configEditor->ReadInt( wxT( "/config/other/encoding" ), 41 ) + 1 );
    wxBoxSizer *bsH1 = new wxBoxSizer( wxHORIZONTAL );
    bsH1->Add( stEncoding, 0, wxEXPAND | wxLEFT, 10 );
    bsH1->Add( cbEncoding, 0, wxEXPAND | wxLEFT, 10 );
    sbs->Add( bsH1, 0, wxEXPAND | wxTOP, 10 );

    const wxString choicesSpaces[]={ wxT( "No" ), wxT( "Always" ), wxT( "After indent" ) };
    stShowSpaces = new wxStaticText( this, wxID_ANY, wxT( "Show spaces" ) );
    cbShowSpaces = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 3, choicesSpaces, wxCB_READONLY );
    cbShowSpaces->SetSelection( configEditor->ReadInt( wxT( "/config/other/showspaces" ), 0 ) );
    wxBoxSizer *bsH2 = new wxBoxSizer( wxHORIZONTAL );
    bsH2->Add( stShowSpaces, 0, wxEXPAND | wxLEFT, 10 );
    bsH2->Add( cbShowSpaces, 0, wxEXPAND | wxLEFT, 10 );
    sbs->Add( bsH2, 0, wxEXPAND | wxTOP, 10 );


    cbWordWrap = new wxCheckBox( this, wxID_ANY, wxT( "Word wrap" ) );
    cbWordWrap->SetValue( configEditor->ReadBool( wxT( "/config/other/wordwrap" ), false ) );
    sbs->Add( cbWordWrap, 0, wxEXPAND | wxTOP | wxLEFT, 10 );


    cbShowLN = new wxCheckBox( this, wxID_ANY, wxT( "Show line number" ) );
    cbShowLN->SetValue( configEditor->ReadBool( wxT( "/config/other/showln" ), true ) );
    sbs->Add( cbShowLN, 0, wxEXPAND | wxTOP | wxLEFT, 10 );


    SetSizer( sbs );

}

iaOthersPanel::~iaOthersPanel()
{

}

void iaOthersPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    configEditor->WriteInt( wxT( "/config/other/encoding" ), cbEncoding->GetSelection()-1 );
    configEditor->WriteInt( wxT( "/config/other/showspaces" ), cbShowSpaces->GetSelection() );
    configEditor->WriteBool( wxT( "/config/other/wordwrap" ), cbWordWrap->GetValue() );
    configEditor->WriteBool( wxT( "/config/other/showln" ), cbShowLN->GetValue() );
}

/////////////////////////////////////////





///CODE COMPLETION
iaSettingsCodeCompletion::iaSettingsCodeCompletion( wxWindow *parent )
    : iaSettingsScrolledWindow( parent )
{
    wxBoxSizer *bsVertical = new wxBoxSizer( wxVERTICAL );
    iaSettingsPanel *ccp = new iaCodeCompletionPanel( this );
    vectorPanel.push_back( ccp );
    bsVertical->Add( ccp, 1, wxEXPAND );

    //FitInside();
    //SetScrollRate( 5, 5 );
    SetSizer( bsVertical );
}

iaSettingsCodeCompletion::~iaSettingsCodeCompletion()
{

}


void iaSettingsCodeCompletion::WriteConfig()
{
    for( size_t i=0; i<vectorPanel.size(); ++i )
        vectorPanel[i]->WriteConfig();
}




BEGIN_EVENT_TABLE( iaCodeCompletionPanel, iaSettingsPanel )
    EVT_CHECKBOX( iaID_CB_CODE_COMPLETION, iaCodeCompletionPanel::OnCodeCompletion )
END_EVENT_TABLE()

iaCodeCompletionPanel::iaCodeCompletionPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxBoxSizer *bsVertical = new wxBoxSizer( wxVERTICAL );

    const bool flagEnable( configEditor->ReadBool( wxT( "/config/codecompletion/autocomplete" ), true ) );
    cbCodeCompletion = new wxCheckBox( this, iaID_CB_CODE_COMPLETION, wxT( "Enable code-completion" ) );
    cbCodeCompletion->SetValue( flagEnable );
    bsVertical->Add( cbCodeCompletion, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10 );

    wxStaticBoxSizer *sbsOptions = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " Options " ) );

    wxBoxSizer *sbsNL = new wxBoxSizer( wxHORIZONTAL );
    stNumberLetters = new wxStaticText( this, wxID_ANY, wxT( "Launch when typed # letters" ) );
    scNumberLetters = new wxSpinCtrl( this );
    scNumberLetters->SetRange( 0, 10 );
    scNumberLetters->SetValue( configEditor->ReadInt( wxT( "/config/codecompletion/numberletters" ), 3 ) );
    sbsNL->Add( stNumberLetters, 0, wxALIGN_CENTRE_VERTICAL );
    sbsNL->Add( scNumberLetters, 0 );
    sbsOptions->Add( sbsNL, 0, wxEXPAND | wxTOP | wxLEFT, 10 );

    cbSensitive = new wxCheckBox( this, wxID_ANY, wxT( "Case sensitive match" ) );
    cbSensitive->SetValue( configEditor->ReadBool( wxT( "/config/codecompletion/sensitive" ), false ) );
    sbsOptions->Add( cbSensitive, 0, wxEXPAND | wxLEFT, 10 );

    cbDropRest = new wxCheckBox( this, wxID_ANY, wxT( "Drop rest of word" ) );
    cbDropRest->SetValue( configEditor->ReadBool( wxT( "/config/codecompletion/droprest" ), true ) );
    sbsOptions->Add( cbDropRest, 0, wxEXPAND | wxLEFT | wxBOTTOM, 10 );

    bsVertical->Add( sbsOptions, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10 );


    SetSizer( bsVertical );

    stNumberLetters->Enable( flagEnable );
    scNumberLetters->Enable( flagEnable );
    cbSensitive->Enable( flagEnable );
    cbDropRest->Enable( flagEnable );
}

iaCodeCompletionPanel::~iaCodeCompletionPanel()
{

}

void iaCodeCompletionPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    bool flag( cbCodeCompletion->GetValue() );
    configEditor->WriteBool( wxT( "/config/codecompletion/autocomplete" ), flag );
    if( flag )
    {
        configEditor->WriteInt( wxT( "/config/codecompletion/numberletters" ), scNumberLetters->GetValue() );
        configEditor->WriteBool( wxT( "/config/codecompletion/sensitive" ), cbSensitive->GetValue() );
        configEditor->WriteBool( wxT( "/config/codecompletion/droprest" ), cbDropRest->GetValue() );
    }
}

void iaCodeCompletionPanel::OnCodeCompletion( wxCommandEvent &evt )
{
    stNumberLetters->Enable( evt.IsChecked() );
    scNumberLetters->Enable( evt.IsChecked() );
    cbSensitive->Enable( evt.IsChecked() );
    cbDropRest->Enable( evt.IsChecked() );
}
////////////////////////////////////////



///FOLD
iaSettingsFold::iaSettingsFold( wxWindow *parent )
    : iaSettingsScrolledWindow( parent )
{
    wxBoxSizer *bsVertical = new wxBoxSizer( wxVERTICAL );
    iaSettingsPanel *fp = new iaFoldPanel( this );
    vectorPanel.push_back( fp );
    bsVertical->Add( fp, 1, wxEXPAND );

    //FitInside();
    //SetScrollRate( 5, 5 );
    SetSizer( bsVertical );
}

iaSettingsFold::~iaSettingsFold()
{

}

void iaSettingsFold::WriteConfig()
{
    for( size_t i=0; i<vectorPanel.size(); ++i )
        vectorPanel[i]->WriteConfig();
}






BEGIN_EVENT_TABLE( iaFoldPanel, iaSettingsPanel )
    EVT_CHECKBOX( iaID_CB_FOLD, iaFoldPanel::OnFold )
    EVT_BUTTON( iaID_BTN_FOLD_BACKGROUND, iaFoldPanel::OnButtonColour )
    EVT_BUTTON( iaID_BTN_FOLD_FOREGROUND, iaFoldPanel::OnButtonColour )
END_EVENT_TABLE()

iaFoldPanel::iaFoldPanel( wxWindow *parent )
    : iaSettingsPanel( parent )
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    wxBoxSizer *bsVertical = new wxBoxSizer( wxVERTICAL );

    const bool enable( configEditor->ReadBool( wxT( "/config/fold/enable" ), true ) );
    cbFold = new wxCheckBox( this, iaID_CB_FOLD, wxT( "Enable fold" ) );
    cbFold->SetValue( enable );
    bsVertical->Add( cbFold, 0, wxEXPAND | wxLEFT | wxTOP, 10 );

    cbUnderLine = new wxCheckBox( this, wxID_ANY, wxT( "Underline folded line" ) );
    cbUnderLine->SetValue( configEditor->ReadBool( wxT( "/config/fold/underline" ), true ) );
    bsVertical->Add( cbUnderLine, 0, wxEXPAND | wxLEFT, 10 );

    cbFoldComment = new wxCheckBox( this, wxID_ANY, wxT( "Fold comment" ) );
    cbFoldComment->SetValue( configEditor->ReadBool( wxT( "/config/fold/foldcomment" ), true ) );
    bsVertical->Add( cbFoldComment, 0, wxEXPAND | wxLEFT, 10 );

    const wxString choices[]={ wxT( "circle" ), wxT( "Round rect" ), wxT( "Arrow" ),
		wxT( "Small rect" ), wxT( "Short arrow" ), wxT( "Empty" ), wxT( "Arrow down" ),
		wxT( "Minus" ), wxT( "Plus" ), wxT( "V line" ), wxT( "L corner" ),
		wxT( "T corner" ), wxT( "Box plus" ), wxT( "Box plus connected" ), wxT( "Box minus" ),
		wxT( "Box minus connected" ), wxT( "L corner curve" ), wxT( "T corner curve" ), wxT( "Circle plus" ),
		wxT( "Circle plus connected" ), wxT( "Circle minus" ), wxT( "Circle minus connected" ), wxT( "Background" ),
		wxT( "Dot Dot Dot" ), wxT( "Arrows" ) };

    wxStaticBoxSizer *sbsMarks = new wxStaticBoxSizer( wxVERTICAL, this, wxT( " Marks " ) );

    wxFlexGridSizer *gsSizer = new wxFlexGridSizer( 7, 4, 5, 0 );

    btnFolderBack = new wxButton( this, iaID_BTN_FOLD_BACKGROUND, wxT( "Background" ) );
    btnFolderFore = new wxButton( this, iaID_BTN_FOLD_FOREGROUND, wxT( "Foreground" ) );
    btnFolderFore->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/folder/foreground" ), wxT( "#FFFFFF" ) ) );
    btnFolderBack->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/folder/background" ), wxT( "#000000" ) ) );
    stFolder = new wxStaticText( this, wxID_ANY, wxT( "Folder" ) );
    cbFolder = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 25, choices, wxCB_READONLY );
    cbFolder->SetSelection( configEditor->ReadInt( wxT( "/config/fold/folder/symbol" ), 12 ) );
    gsSizer->Add( stFolder, 0, wxALIGN_CENTRE_VERTICAL );
    gsSizer->Add( cbFolder, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, 10 );
    gsSizer->Add( btnFolderBack, 0, wxLEFT, 10 );
    gsSizer->Add( btnFolderFore, 0, wxLEFT, 10 );

    btnFolderOpenBack = new wxButton( this, iaID_BTN_FOLD_BACKGROUND, wxT( "Background" ) );
    btnFolderOpenFore = new wxButton( this, iaID_BTN_FOLD_FOREGROUND, wxT( "Foreground" ) );
    btnFolderOpenFore->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/folderopen/foreground" ), wxT( "#FFFFFF" ) ) );
    btnFolderOpenBack->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/folderopen/background" ), wxT( "#000000" ) ) );
    stFolderOpen = new wxStaticText( this, wxID_ANY, wxT( "Folder open" ) );
    cbFolderOpen = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 25, choices, wxCB_READONLY );
    cbFolderOpen->SetSelection( configEditor->ReadInt( wxT( "/config/fold/folderopen/symbol" ), 14 ) );
    gsSizer->Add( stFolderOpen, 0, wxALIGN_CENTRE_VERTICAL );
    gsSizer->Add( cbFolderOpen, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, 10 );
    gsSizer->Add( btnFolderOpenBack, 0, wxLEFT, 10 );
    gsSizer->Add( btnFolderOpenFore, 0, wxLEFT, 10 );

    btnFolderSubBack = new wxButton( this, iaID_BTN_FOLD_BACKGROUND, wxT( "Background" ) );
    btnFolderSubFore = new wxButton( this, iaID_BTN_FOLD_FOREGROUND, wxT( "Foreground" ) );
    btnFolderSubFore->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/foldersub/foreground" ), wxT( "#000000" ) ) );
    btnFolderSubBack->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/foldersub/background" ), wxT( "#000000" ) ) );
    stFolderSub = new wxStaticText( this, wxID_ANY, wxT( "Folder sub" ) );
    cbFolderSub = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 25, choices, wxCB_READONLY );
    cbFolderSub->SetSelection( configEditor->ReadInt( wxT( "/config/fold/foldersub/symbol" ), 9 ) );
    gsSizer->Add( stFolderSub, 0, wxALIGN_CENTRE_VERTICAL );
    gsSizer->Add( cbFolderSub, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, 10 );
    gsSizer->Add( btnFolderSubBack, 0, wxLEFT, 10 );
    gsSizer->Add( btnFolderSubFore, 0, wxLEFT, 10 );

    btnFolderEndBack = new wxButton( this, iaID_BTN_FOLD_BACKGROUND, wxT( "Background" ) );
    btnFolderEndFore = new wxButton( this, iaID_BTN_FOLD_FOREGROUND, wxT( "Foreground" ) );
    btnFolderEndFore->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/folderend/foreground" ), wxT( "#FFFFFF" ) ) );
    btnFolderEndBack->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/folderend/background" ), wxT( "#000000" ) ) );
    stFolderEnd = new wxStaticText( this, wxID_ANY, wxT( "Folder end" ) );
    cbFolderEnd = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 25, choices, wxCB_READONLY );
    cbFolderEnd->SetSelection( configEditor->ReadInt( wxT( "/config/fold/folderend/symbol" ), 13 ) );
    gsSizer->Add( stFolderEnd, 0, wxALIGN_CENTRE_VERTICAL );
    gsSizer->Add( cbFolderEnd, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, 10 );
    gsSizer->Add( btnFolderEndBack, 0, wxLEFT, 10 );
    gsSizer->Add( btnFolderEndFore, 0, wxLEFT, 10 );

    btnFolderMidBack = new wxButton( this, iaID_BTN_FOLD_BACKGROUND, wxT( "Background" ) );
    btnFolderMidFore = new wxButton( this, iaID_BTN_FOLD_FOREGROUND, wxT( "Foreground" ) );
    btnFolderMidFore->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/foldermid/foreground" ), wxT( "#FFFFFF" ) ) );
    btnFolderMidBack->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/foldermid/background" ), wxT( "#000000" ) ) );
    stFolderMid = new wxStaticText( this, wxID_ANY, wxT( "Folder mid" ) );
    cbFolderMid = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 25, choices, wxCB_READONLY );
    cbFolderMid->SetSelection( configEditor->ReadInt( wxT( "/config/fold/foldermid/symbol" ), 15 ) );
    gsSizer->Add( stFolderMid, 0, wxALIGN_CENTRE_VERTICAL );
    gsSizer->Add( cbFolderMid, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, 10 );
    gsSizer->Add( btnFolderMidBack, 0, wxLEFT, 10 );
    gsSizer->Add( btnFolderMidFore, 0, wxLEFT, 10 );

    btnFolderMidTailBack = new wxButton( this, iaID_BTN_FOLD_BACKGROUND, wxT( "Background" ) );
    btnFolderMidTailFore  = new wxButton( this, iaID_BTN_FOLD_FOREGROUND, wxT( "Foreground" ) );
    btnFolderMidTailFore->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/foldermidtail/foreground" ), wxT( "#000000" ) ) );
    btnFolderMidTailBack->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/foldermidtail/background" ), wxT( "#000000" ) ) );
    stFolderMidTail = new wxStaticText( this, wxID_ANY, wxT( "Folder mid tail" ) );
    cbFolderMidTail = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 25, choices, wxCB_READONLY );
    cbFolderMidTail->SetSelection( configEditor->ReadInt( wxT( "/config/fold/foldermidtail/symbol" ), 11 ) );
    gsSizer->Add( stFolderMidTail, 0, wxALIGN_CENTRE_VERTICAL );
    gsSizer->Add( cbFolderMidTail, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, 10 );
    gsSizer->Add( btnFolderMidTailBack, 0, wxLEFT, 10 );
    gsSizer->Add( btnFolderMidTailFore, 0, wxLEFT, 10 );


    btnFolderTailBack = new wxButton( this, iaID_BTN_FOLD_BACKGROUND, wxT( "Background" ) );
    btnFolderTailFore = new wxButton( this, iaID_BTN_FOLD_FOREGROUND, wxT( "Foreground" ) );
    btnFolderTailFore->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/foldertail/foreground" ), wxT( "#000000" ) ) );
    btnFolderTailBack->SetBackgroundColour( configEditor->ReadString( wxT( "/config/fold/foldertail/background" ), wxT( "#000000" ) ) );
    stFolderTail = new wxStaticText( this, wxID_ANY, wxT( "Folder tail" ) );
    cbFolderTail = new wxComboBox( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize, 25, choices, wxCB_READONLY );
    cbFolderTail->SetSelection( configEditor->ReadInt( wxT( "/config/fold/foldertail/symbol" ), 10 ) );
    gsSizer->Add( stFolderTail, 0, wxALIGN_CENTRE_VERTICAL );
    gsSizer->Add( cbFolderTail, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, 10 );
    gsSizer->Add( btnFolderTailBack, 0, wxLEFT, 10 );
    gsSizer->Add( btnFolderTailFore, 0, wxLEFT, 10 );

    sbsMarks->AddSpacer( 10 );
    sbsMarks->Add( gsSizer, 0, wxEXPAND | wxLEFT, 20 );
    sbsMarks->AddSpacer( 10 );

    bsVertical->Add( sbsMarks, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10 );

    SetSizer( bsVertical );




    cbUnderLine->Enable( enable );
    cbFoldComment->Enable( enable );

    stFolder->Enable( enable );
    cbFolder->Enable( enable );
    btnFolderBack->Enable( enable );
    btnFolderFore->Enable( enable );

    stFolderOpen->Enable( enable );
    cbFolderOpen->Enable( enable );
    btnFolderOpenBack->Enable( enable );
    btnFolderOpenFore->Enable( enable );

    stFolderSub->Enable( enable );
    cbFolderSub->Enable( enable );
    btnFolderSubBack->Enable( enable );
    btnFolderSubFore->Enable( enable );

    stFolderEnd->Enable( enable );
    cbFolderEnd->Enable( enable );
    btnFolderEndBack->Enable( enable );
    btnFolderEndFore->Enable( enable );

    stFolderMid->Enable( enable );
    cbFolderMid->Enable( enable );
    btnFolderMidBack->Enable( enable );
    btnFolderMidFore->Enable( enable );

    stFolderMidTail->Enable( enable );
    cbFolderMidTail->Enable( enable );
    btnFolderMidTailBack->Enable( enable );
    btnFolderMidTailFore->Enable( enable );

    stFolderTail->Enable( enable );
    cbFolderTail->Enable( enable );
    btnFolderTailBack->Enable( enable );
    btnFolderTailFore->Enable( enable );
}

iaFoldPanel::~iaFoldPanel()
{

}

void iaFoldPanel::WriteConfig()
{
    sdk::FileConfig *configEditor = sdk::ConfigManager::Get()->GetFile( sdk::Editor::s_fileConfig );

    const bool flagFold( cbFold->GetValue() );

    configEditor->WriteBool( wxT( "/config/fold/enable" ), flagFold );

    if( flagFold )
    {
        configEditor->WriteBool( wxT( "/config/fold/underline" ), cbUnderLine->GetValue() );
        configEditor->WriteBool( wxT( "/config/fold/foldcomment" ), cbFoldComment->GetValue() );


        configEditor->WriteColour( wxT( "/config/fold/folder/background" ), btnFolderBack->GetBackgroundColour() );
        configEditor->WriteColour( wxT( "/config/fold/folder/foreground" ), btnFolderFore->GetBackgroundColour() );
        configEditor->WriteInt( wxT( "/config/fold/folder/symbol" ), cbFolder->GetSelection() );


        configEditor->WriteColour( wxT( "/config/fold/folderopen/background" ), btnFolderOpenBack->GetBackgroundColour() );
        configEditor->WriteColour( wxT( "/config/fold/folderopen/foreground" ), btnFolderOpenFore->GetBackgroundColour() );
        configEditor->WriteInt( wxT( "/config/fold/folderopen/symbol" ), cbFolderOpen->GetSelection() );

        configEditor->WriteColour( wxT( "/config/fold/foldersub/background" ), btnFolderSubBack->GetBackgroundColour() );
        configEditor->WriteColour( wxT( "/config/fold/foldersub/foreground" ), btnFolderSubFore->GetBackgroundColour() );
        configEditor->WriteInt( wxT( "/config/fold/foldersub/symbol" ), cbFolderSub->GetSelection() );


        configEditor->WriteColour( wxT( "/config/fold/folderend/background" ), btnFolderEndBack->GetBackgroundColour() );
        configEditor->WriteColour( wxT( "/config/fold/folderend/foreground" ), btnFolderEndFore->GetBackgroundColour() );
        configEditor->WriteInt( wxT( "/config/fold/folderend/symbol" ), cbFolderEnd->GetSelection() );


        configEditor->WriteColour( wxT( "/config/fold/foldermid/background" ), btnFolderMidBack->GetBackgroundColour() );
        configEditor->WriteColour( wxT( "/config/fold/foldermid/foreground" ), btnFolderMidFore->GetBackgroundColour() );
        configEditor->WriteInt( wxT( "/config/fold/foldermid/symbol" ), cbFolderMid->GetSelection() );


        configEditor->WriteColour( wxT( "/config/fold/foldermidtail/background" ), btnFolderMidTailBack->GetBackgroundColour() );
        configEditor->WriteColour( wxT( "/config/fold/foldermidtail/foreground" ), btnFolderMidTailFore->GetBackgroundColour() );
        configEditor->WriteInt( wxT( "/config/fold/foldermidtail/symbol" ), cbFolderMidTail->GetSelection() );



        configEditor->WriteColour( wxT( "/config/fold/foldertail/background" ), btnFolderTailBack->GetBackgroundColour() );
        configEditor->WriteColour( wxT( "/config/fold/foldertail/foreground" ), btnFolderTailFore->GetBackgroundColour() );
        configEditor->WriteInt( wxT( "/config/fold/foldertail/symbol" ), cbFolderTail->GetSelection() );

    }
}

void iaFoldPanel::OnFold( wxCommandEvent &evt )
{
    const bool enable( evt.IsChecked() );

    cbUnderLine->Enable( enable );
    cbFoldComment->Enable( enable );

    stFolder->Enable( enable );
    cbFolder->Enable( enable );
    btnFolderBack->Enable( enable );
    btnFolderFore->Enable( enable );

    stFolderOpen->Enable( enable );
    cbFolderOpen->Enable( enable );
    btnFolderOpenBack->Enable( enable );
    btnFolderOpenFore->Enable( enable );

    stFolderSub->Enable( enable );
    cbFolderSub->Enable( enable );
    btnFolderSubBack->Enable( enable );
    btnFolderSubFore->Enable( enable );

    stFolderEnd->Enable( enable );
    cbFolderEnd->Enable( enable );
    btnFolderEndBack->Enable( enable );
    btnFolderEndFore->Enable( enable );

    stFolderMid->Enable( enable );
    cbFolderMid->Enable( enable );
    btnFolderMidBack->Enable( enable );
    btnFolderMidFore->Enable( enable );

    stFolderMidTail->Enable( enable );
    cbFolderMidTail->Enable( enable );
    btnFolderMidTailBack->Enable( enable );
    btnFolderMidTailFore->Enable( enable );

    stFolderTail->Enable( enable );
    cbFolderTail->Enable( enable );
    btnFolderTailBack->Enable( enable );
    btnFolderTailFore->Enable( enable );
}

void iaFoldPanel::OnButtonColour( wxCommandEvent &evt )
{
    wxColourData data;
    data.SetColour( static_cast<wxButton *>( evt.GetEventObject() )->GetBackgroundColour() );
    wxColourDialog dlg( this, &data );

    if( dlg.ShowModal() == wxID_OK )
        static_cast<wxButton *>( evt.GetEventObject() )->SetBackgroundColour( dlg.GetColourData().GetColour() );
}
